package org.example.spring.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.example.spring.domain.dto.FlowerDTO;
import org.example.spring.domain.pojo.Flower;

import java.util.ArrayList;

@Mapper
public interface FlowerMapper {
    @Select("SELECT * FROM flowers")
    ArrayList<Flower> getAllFlower();

    @Select("SELECT COUNT(*) FROM flowers WHERE category = #{categoryName}")
    int getCount(String categoryName);

    Page<Flower> getPageFlower(FlowerDTO flowerPageDTO);

    @Delete("DELETE FROM flowers WHERE flower_id = #{id}")
    void deleteFlowerById(int id);


    void updateFlower(Flower flower);

    @Insert("INSERT INTO flowers (name, price, description, category,image_url) " +
            "VALUES (#{name}, #{price}, #{description}, #{category},#{imageUrl})")
    void addFlower(Flower flower);

    @Update("UPDATE flowers SET   category = #{categoryName} WHERE category = #{olderCategoryName}")
    void updateCategoryName(String olderCategoryName, String categoryName);

    @Select("SELECT name FROM flowers WHERE flower_id = #{flowerId}")
    String getFlowerNameById(Integer flowerId);

    @Select("SELECT image_url FROM flowers order by sales")
    ArrayList<String> getFlowerImage();

    @Select("SELECT * FROM flowers WHERE sales > 0 order by sales desc limit 4")
    ArrayList<Flower> getHotFlower();

    @Select("SELECT * FROM flowers WHERE flower_id = #{id}")
    Flower getFlowerById(Integer id);


    int getTotalFlower(FlowerDTO flowerPageDTO);

    ArrayList<Flower> getFlowerByIds(ArrayList<Integer> ids);
}
